$(function () {
    //上报统计
    getRecordData();
    //日期框
    $('.date-picker').datepicker({autoclose: true, todayHighlight: true});
});
/**
 * 获取上报统计
 */
function getRecordData() {
    var url = ctx + "mainDataYingji";
    $.ajax({
        cache : true,
        type : "POST",
        data : {
            beginTime : $('#beginTime').val(),endTime : $('#endTime').val(),
        },
        url : url,
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            console.log('data',data);
            var townsName = data.townsName;
            var recordsCount0 = data.recordsCount0;
            var recordsCount1 = data.recordsCount1;
            var lineChart = echarts.init(document.getElementById("echarts-line-chart"));
            var lineoption = {
                tooltip : {
                    // trigger: 'axis',
                    show : true
                },
                grid:{
                    x:50,y:10,x2:5
                },
                calculable : true,
                xAxis : {
                    type: 'category',
                    data: townsName,
                    axisLabel:{
                        interval:0,//横轴全部显示
                        formatter: function(value) {
                            return value.split('').join('\n')
                        },
                    },
                },
                yAxis : [
                    {
                        type : 'value',
                        axisLabel : {
                            formatter: '{value}'
                        }
                    }
                ],
                series : [
                    {
                        barWidth : 18,//柱图宽度
                        type:'bar',
                        data:recordsCount0,
                        itemStyle: {
                            normal: {
                                label: {
                                    show: true, //开启显示
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: 'blue',
                                        fontSize: 16
                                    }
                                }
                            }
                        },
                    }
                ]
            };
            lineChart.setOption(lineoption);
            $(window).resize(lineChart.resize);

            var barChart = echarts.init(document.getElementById("echarts-bar-chart"));
            var baroption = {
                tooltip : {
                    // trigger: 'axis',
                    show:true
                },
                grid:{
                    x:50,y:10,x2:5
                },
                calculable : true,
                xAxis :{
                    type: 'category',
                    data: townsName,
                    axisLabel:{
                        interval:0,//横轴全部显示
                        formatter: function(value) {
                            return value.split('').join('\n')
                        },
                    },
                },
                yAxis : [
                    {
                        type : 'value'
                    }
                ],
                series :[
                    {
                        barWidth : 18,//柱图宽度
                        type:'bar',
                        data:recordsCount1,
                        itemStyle: {
                            normal: {
                                label: {
                                    show: true, //开启显示
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: 'blue',
                                        fontSize: 16
                                    }
                                }
                            }
                        },
                    }
                ]
            };
            barChart.setOption(baroption);
            window.onresize = barChart.resize;
        }
    });
}
